<template>
  <a-spin :loading="loading" style="width: 100%">
    <a-card
      class="general-card"
      
    >
      <Chart style="width: 100%; height: 300px" :option="chartOption" />
    </a-card>
  </a-spin>
</template>

<script lang="ts" setup>
import useLoading from '../../hooks/loading';
import useChartOption from '../../hooks/chart-option';
import { defineProps } from 'vue';

// 定义接收的 props
const props = defineProps({
    domainCount: {
        type: Number,
        default: 0
    },
    ipCount: {
        type: Number,
        default: 0
    }
});

const { chartOption } = useChartOption((isDark) => {
  const graphicElementStyle = {
    textAlign: 'center',
    fill: isDark ? 'rgba(255,255,255,0.7)' : '#4E5969',
    fontSize: 14,
    lineWidth: 10,
    fontWeight: 'bold',
  };
  return {
    legend: {
      left: 'center',
      data: ['域名', 'IP'],
      bottom: 0,
      icon: 'circle',
      itemWidth: 8,
      textStyle: {
        color: isDark ? 'rgba(255,255,255,0.7)' : '#4E5969',
      },
      itemStyle: {
        borderWidth: 0,
      },
    },
    tooltip: {
      show: true,
      trigger: 'item',
    },
    series: [
      {
        type: 'pie',
        radius: ['50%', '70%'],
        center: ['50%', '50%'],
        label: {
          formatter: '{d}% ',
          color: isDark ? 'rgba(255, 255, 255, 0.7)' : '#4E5969',
        },
        itemStyle: {
          borderColor: isDark ? '#000' : '#fff',
          borderWidth: 1,
        },
        data: [
          {
            value: props.domainCount,
            name: '域名',
            itemStyle: {
              color: '#249EFF',
            },
          },
          {
            value: props.ipCount,
            name: 'IP',
            itemStyle: {
              color: '#846BCE',
            },
          },
        ],
      },
    ],
    // 添加 graphic 组件，将文字放在图表中间
    graphic: [
      {
        type: 'text',
        left: 'center',
        top: 'center',
        style: {
          text: 'IOC数量',
          textAlign: 'center',
          fill: isDark ? 'rgba(255,255,255,0.7)' : '#4E5969',
          fontSize: 20,
          fontWeight: 'bold'
        }
      }
    ]
  };
});
const { loading } = useLoading(false);
</script>

<style scoped lang="less"></style>